package com.printer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

@Component("printer")
public class Printer {
    @Autowired
    @Qualifier("colorInk")
    private Ink ink;

    @Autowired
    private Paper paper;


    /**
     * 设值注入所需的setter方法。
     * @param ink 墨盒
     */
    public void setInk(Ink ink) {
        this.ink = ink;
    }

    /**
     * 设值注入所需的setter方法。
     * @param paper 纸张
     */
    public void setPaper(Paper paper) {
        this.paper = paper;
    }

    /**
     * 打印方法
     * @param message 要打印内容
     */
    public void print(String message) {

        int random=(int)(Math.random()*10);
        if (random>5){
            System.out.println("正在打印");
        }else if(random>7){
            System.out.println("抛出卡牌异常");
        }else if(random>=9){
            System.out.println("墨盒无莫的异常");
        }
        // 输出颜色标记
        System.out.println("使用" + ink.getColor(255, 200, 0) + "颜色打印:\n");
        // 逐字符输出到纸张
        for (int i = 0; i < message.length(); ++i) {
            paper.putInChar(message.charAt(i));
        }
        // 将纸张的内容输出
        System.out.print(paper.getContent());
    }

}
